package com.asia5b.a5mall.middleware.logic.viewmodel.member

import androidx.lifecycle.MutableLiveData
import com.asia5b.a5mall.middleware.R
import com.asia5b.a5mall.middleware.base.SimpleViewModel
import com.asia5b.a5mall.middleware.model.member.AddressModel
import com.asia5b.a5mall.middleware.utils.showMessage
import io.reactivex.functions.Consumer

/**
 * Created by zhangyuncai on 2020/1/8.
 */
class AddressListActivityVM :SimpleViewModel() {

    fun loadAddress() {
        val observable = memberApi.getAddressList()
        baseSubscribe(observable, Consumer { result ->
//            providerView().loadAddressResult(result)
            loadAddressResultLiveData.value=result
        })
    }
    val loadAddressResultLiveData= MutableLiveData<ArrayList<AddressModel>>()
    fun delete(id: Int) {
        baseSubscribe(memberApi.deleteAddress(id), Consumer {
            showMessage(R.string.删除成功)
            loadAddress()
        })
    }

    fun setDefalut(id: Int) {
        baseSubscribe(memberApi.setAddressDefault(id), Consumer {
            loadAddress()
        })
    }
}